import { Comment } from 'src/comment/comment.entity';
import { Tag } from 'src/tag/tag.entity';
import { Type } from 'src/type/type.entity';
import { User } from 'src/user/user.entity';
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, ManyToMany, JoinTable, OneToMany, RelationId } from 'typeorm';

@Entity()
export class Blog {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        nullable: false
    })
    title: string;

    @Column({
        type: "longtext"
    })
    introduction: string


    @Column({
        nullable: false,
        type: "longtext"
    })
    content: string;

    @Column({
        nullable: false
    })
    firstPicture: string;

    @Column()
    views: number;

    @CreateDateColumn({
        type: "timestamp",
        comment: '创建时间'
    })
    createTime: Date

    @UpdateDateColumn({
        type: "timestamp",
        comment: '更新时间'
    })
    updateTime: Date

    @ManyToMany(type => Tag, tag => tag.blogs)
    @JoinTable()
    tags: Tag[]

    @ManyToOne(type=>Type, type => type.blogs)
    type: Type

    @RelationId((blog: Blog) => blog.type)
    typeId: number 

    @ManyToOne(type=> User, user => user.blogs)
    user: User

    @RelationId((blog: Blog) => blog.user)
    userId: number 

    @OneToMany(type => Comment, comment => comment.blog)
    comments: Comment[]
}